package model

import (
	"gpt-api/framework/db"
)

type TopupWays struct {
	db.BaseModel
	Title        string `json:"title" gorm:"column:title;type:varchar(150);default:'';comment:充值方式"`
	Duration     int    `json:"duration" gorm:"column:duration;type:int;default:0;comment:充值时长"`
	Price        int    `json:"price" gorm:"column:price;type:int;default:0;comment:价格"`
	Discount     int    `json:"discount" gorm:"column:discount;type:int;default:0;comment:折扣价"`
	Subtitle     string `json:"subtitle" gorm:"column:subtitle;type:varchar(150);default:'';comment:副标题"`
	DisplayOrder int    `json:"display_order" gorm:"column:display_order;type:int;default:0;comment:显示顺序"`
	Score        int    `json:"score" gorm:"column:score;type:int;default:0;comment:积分"`
}

func (TopupWays) TableName() string {
	return "topup_ways"
}

func (t *TopupWays) GetTopupWays(database *db.DB) ([]TopupWays, error) {
	var topupWays []TopupWays
	err := database.Find(&topupWays).Order("display_order").Error
	return topupWays, err
}

// 查询单挑充值方式
func (t *TopupWays) GetTopupWayById(database *db.DB, id uint) (TopupWays, error) {
	var topupWay TopupWays
	err := database.Where("id = ?", id).First(&topupWay).Error
	return topupWay, err
}
